package com.qf.ssm.controller;

import com.qf.ssm.common.request.MemberRequestParams;
import com.qf.ssm.common.vo.ResponseResult;
import com.qf.ssm.service.MemberService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author ISALYL
 * @create 2021-10-11 20:01
 */
@RestController
@RequestMapping("/member")
public class MemberController {
    @Resource
    private MemberService memberService;




    /**
     * 点击显示用户收货地址
     *
     * @param memberId
     * @return
     */
    @PostMapping("/address/{memberId}")
    public ResponseResult<String> findAddress(@PathVariable Long memberId) {
        String result = memberService.findAddress(memberId);
        return ResponseResult.success(result);
    }

    /**
     * 注册用户
     * 测试可以区分手机号和用户名是否存在
     *
     * @param params
     * @return
     */
    @PostMapping("/register")
    public ResponseResult<Boolean> register(@RequestBody MemberRequestParams params) {
        boolean register = memberService.register(params);
        if (register) {
            return ResponseResult.success(register);
        } else {
            return ResponseResult.error();
        }
    }

    /**
     * 提交投诉需求
     *
     * @param
     * @return
     */
    @PutMapping("/remark")
    public ResponseResult<Integer> modRemark(@RequestBody MemberRequestParams params) {
        Integer remark = memberService.modRemark(params);
        return ResponseResult.success(remark);
    }

    /**
     * 逻辑删除,将status置0
     * @param memberId
     * @return
     */
    @DeleteMapping("/delete/{memberId}")
    public ResponseResult<Boolean> deleteMember(@PathVariable("memberId") Long memberId){
        Boolean delete = memberService.deleteMember(memberId);
        return ResponseResult.success(delete);
    }



}
